package workexp.alg.question;

import org.junit.Test;

public class ReverseInt {
    public int reverse(int x) {
/*        int sign =1;
        if(x<0){
            sign=-1;
        }*/
        int result = 0;
        while (x!=0){
            int newres = result*10;
            newres+=x%10;
            //如果数字溢出，直接返回0
            if ((newres - x%10) / 10 != result){
                return 0;
            }else{
                result=newres;
            }
            x/=10;
        }
        return result;
    }

    @Test
    public void test(){
        int raw =  -1234;
        int result = reverse(raw);
        System.out.println(result);

    }
}
